# -*- coding: utf-8 -*-

# __date:       2021/6/10
# __author:     Yang Chao
# __function:   Two Sum

from typing import List


class Solution:

    def twoSum(self, nums: List[int], target: int) -> List[int]:
        # 32ms   15.9MB
        maping = {}
        for i, v in enumerate(nums):
            temp = target - v
            if temp in map.keys():
                return [i, maping.get(temp)]
            maping[v] = i

    def twoSum2(self, nums: List[int], target: int) -> List[int]:
        # 512ms   15.1MB
        for i in range(1, len(nums)):
            temp = target - nums[i]
            if temp in nums[:i]:
                return [i, nums.index(temp)]